<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('检查结果列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>检查人：</label>
                            <input type="text" name="checkPeople"/>
                        </li>
                        <li>
                            <label>检查地点：</label>
                            <input type="text" name="checkAddress-like"/>
                        </li>
                        <li>
                            <label>行业类别：</label><select name="hylbdm"
                                                         th:with="type=${@dict.getParamValue('SWJG_DWSSHY')}"
                                                         class="selectpicker">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.itemText}"
                                    th:value="${dict.itemValue}"></option>
                        </select>
                        <li>
                            <label>统计条件： </label>
                            <select id="conditions" name="conditions-like" class="selectpicker">
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "control/result";
    var addressId = [[${addressId}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "检查结果",
            queryParams: {
                "addressId": addressId,
                "token": storage.get("token")
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '结果id',
                    visible: false
                },
                {
                    field: 'checkAddress',
                    title: '检查地点'
                },
                {
                    field: 'checkPeople',
                    title: '检查人'
                },
                {
                    field: 'checkTime',
                    title: '检查时间'
                },
                {
                    field: 'nextCheckTime',
                    title: '下次检查时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-eye"></i> 结果查看</a>';
                    }
                }]
        };
        $.table.responseHandler = function (res) {
            if (typeof table.options.responseHandler == "function") {
                table.options.responseHandler(res);
            }
            if (res.code === 200) {
                if ($.common.isNotEmpty(table.options.sidePagination) && table.options.sidePagination == 'client') {
                    return res.result.list.records;
                } else {
                    if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
                        var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
                        $.each(res.result.list.records, function (i, row) {
                            row.state = $.inArray(row[column], table.rememberSelectedIds[table.options.id]) !== -1;
                        })
                    }
                    var conditionsHtml = '<option value="">请选择</option>';
                    res.result.conditions.forEach(val => {
                        conditionsHtml += '<option value="' + val + '">' + val + '</option>'
                    });
                    $("#conditions").html(conditionsHtml);
                    return {rows: res.result.list.records, total: res.result.list.total};
                }
            } else {
                $.modal.alertWarning(res.message);
                return {rows: [], total: 0};
            }

        };
        $.table.init(options);

    });

    function detail(id) {
        var url = prefix + '/detail/' + id;
        $.modal.openTab("结果查看", $.common.setURL(url));
    }
</script>
</body>
</html>
